package com.anonymous.service.impl;

import com.anonymous.entity.Like;
import com.anonymous.dao.LikeDao;
import com.anonymous.service.LikeService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (Like)表服务实现类
 *
 * @author makejava
 * @since 2022-01-16 11:17:37
 */
@Service("likeService")
public class LikeServiceImpl implements LikeService {
    @Resource
    private LikeDao likeDao;

    /**
     * 通过ID查询单条数据
     *
     * @param likeId 主键
     * @return 实例对象
     */
    @Override
    public Like queryById(Integer likeId) {
        return this.likeDao.queryById(likeId);
    }

    /**
     * 分页查询
     *
     * @param like        筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<Like> queryByPage(Like like, PageRequest pageRequest) {
        long total = this.likeDao.count(like);
        return new PageImpl<>(this.likeDao.queryAllByLimit(like, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param like 实例对象
     * @return 实例对象
     */
    @Override
    public Like insert(Like like) {
        this.likeDao.insert(like);
        return like;
    }

    /**
     * 修改数据
     *
     * @param like 实例对象
     * @return 实例对象
     */
    @Override
    public Like update(Like like) {
        this.likeDao.update(like);
        return this.queryById(like.getLikeId());
    }

    /**
     * 通过主键删除数据
     *
     * @param likeId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer likeId) {
        return this.likeDao.deleteById(likeId) > 0;
    }
}
